#!/bin/bash

# NDK 目录
export ANDROID_NDK=/mnt/nas/work/make/ffmpeg/android/ffmpeg/android-ndk-r21e
# 添加编译工具目录
# 进入  x265 目录/mnt/nas/work/webdav/x265_git
cd x265_git/build/linux
OUTLIB=/mnt/nas/work/make/ffmpeg/android/ffmpeg/arm64-v8a/x265
# 编译工具
export TOOLCHAIN_PREFIX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
export SYSTEMROOT=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
# 添加编译工具目录
export PATH=$TOOLCHAIN_PREFIX/bin:$PATH
export CC=aarch64-linux-android21-clang
export CXX=aarch64-linux-android21-clang++
export AR=aarch64-linux-android-ar
export LD=aarch64-linux-android-ld
export ASM=aarch64-linux-android-as
cmake -G "Unix Makefiles" \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=$ANDROID_NDK \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_ASM_COMPILER=$ASM \
-DCMAKE_AR=$AR \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_SHARED=on \
-DENABLE_CLI=off \
-DSTATIC_LINK_CRT=off \
-DENABLE_TESTS=off \
-DENABLE_DOCS=off \
-DENABLE_INSTALL=on \
-DENABLE_THREADING=tbb \
-DCMAKE_INSTALL_PREFIX=$OUTLIB ../../source

# 修改生成动态库配置文件
sed -i 's/-lpthread/-pthread/g' CMakeFiles/cli.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-shared.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-static.dir/link.txt
make -j4
make install



